package com.kingmed.kmss.admin.modules.ums.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.kingmed.kmss.admin.modules.ums.model.UmsAdmin;
import com.kingmed.kmss.admin.modules.ums.model.UmsAdminOrganizationRelation;
import com.kingmed.kmss.admin.modules.ums.model.UmsOrganization;
import com.kingmed.kmss.admin.qc.AdminQc;
import com.kingmed.kmss.common.dto.admin.ums.OrgNodeDTO;
import com.kingmed.kmss.common.dto.admin.ums.OrganizationDTO;
import com.kingmed.kmss.common.dto.admin.ums.OrganizationTileDTO;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 后台组织机构表 服务类
 * </p>
 */
public interface UmsOrganizationService extends IService<UmsOrganization> {

    List<OrgNodeDTO> selfAndChild(Long orgId);

    String selfAndChildString(Long orgId);

    OrgNodeDTO tree(Long orgId);

    OrgNodeDTO tree3Level(Long orgId);

    OrgNodeDTO tree4Level(Long orgId, Boolean onlyOrg);

    void recursionTreeToList(List<OrgNodeDTO> result, OrgNodeDTO root, OrgNodeDTO parentNode);

    List<UmsOrganization> getByNameKey(String keyword);

    List<UmsOrganization> updateOrg(OrgNodeDTO orgNodeDtoList);

    int deleteOrg(List<Long> orgIdList);

    int availableOrg(List<Long> orgIdList);

    List<UmsAdmin> adminsInOrg(Long orgId);

    Page<UmsAdmin> adminsInOrgAndChild(AdminQc adminQc);

    /**
     * 根据组织编码查询组织全称
     *
     * @param orgCode
     * @return
     */
    String findAdminOrgFullName(String orgCode);

    List<UmsAdmin> allAdminsInOrg(AdminQc adminQc);

    void addAdminsInOrg(List<UmsAdminOrganizationRelation> relations);

    void deleteAdminsInOrg(List<UmsAdminOrganizationRelation> relations);

    UmsOrganization getBranchOrg(List<UmsOrganization> allOrg, Long orgId);

    List<UmsOrganization> getParentUpList(List<UmsOrganization> allOrg, Long orgId);

    List<UmsOrganization> loadAllOrg();

    List<OrganizationDTO> getSubsidiaryByAdminId(Long adminId);

    List<OrganizationDTO> getBranchesByOrgId(Long orgId);

    List<OrganizationDTO> getRegions();

    List<OrganizationDTO> getRegionsBySql();

    List<OrganizationDTO> getAllSubsidiary();

    Map<Long, OrganizationDTO> getOrgByIds(List<Long> orgIds);

    /**
     * 组织机构DTO：所属集团、大区、子公司平铺
     */
    OrganizationTileDTO getOrgGroupRegionBranchByOrgId(Long orgId);

    OrgNodeDTO queryPermissionOrg(Long adminId);

    OrgNodeDTO queryPermissionByOrgId(Long orgId);

    /**
     * 更新组织缓存
     *
     * @return
     */
    List<UmsOrganization> redisAllOrg();

    List<OrgNodeDTO> directChild(Long orgId);

    OrgNodeDTO levelThreeOrgTree();

    List<OrganizationDTO> groupRegionBranch(Integer orgLevel);

    String getAdminOrgFullName(Long orgId);

}
